const resolve = require('path').resolve
const webpack = require('webpack')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const url = require('url')
const publicPath = './'
const path = require('path')
const CopyWebpackPlugin = require('copy-webpack-plugin')
resolve('node_modules/element-ui/packages/row/src/row.js')
 
module.exports = (options = {}) => ({
  entry: {
    vendor: './src/vendor',
    index: './src/main.js'
  },
  output: {
    path: resolve(__dirname, 'dist'),
    filename: options.dev ? '[name].js' : '[name].js?[chunkhash]',
    chunkFilename: '[id].js?[chunkhash]',
    publicPath: options.dev ? '/assets/' : publicPath
  },
  module: {
    rules: [{
        test: /\.vue$/,
        use: ['vue-loader']
      },
      {
        test: /\.js$/,
        use: ['babel-loader'],
        exclude: /node_modules/
      },
      {
        test: /\.css$/,
        use: ['style-loader', 'css-loader', 'postcss-loader']
      },
      {
        test: /\.(eot|ttf|woff|woff2|svg|svgz)(\?.+)?$/,
        use: [{
          loader: 'url-loader',
          options: {
            limit: 10000,
			name:'img/[name].[ext]'
          },
		  
        }]
      },
	  {
	    test: /\.(png|jpg|jpeg|gif|mp3)(\?.+)?$/,
	    use: [{
	      loader: 'url-loader',
	      options: {
	        limit: 10000,
			name:'img/[name].[ext]'
	      },
	  		  
	    }]
	  }
    ]
  },
  plugins: [
    new webpack.optimize.CommonsChunkPlugin({
      names: ['vendor', 'manifest']
    }),
    new HtmlWebpackPlugin({
      template: 'src/index.html'
    }),
	// new CopyWebpackPlugin([
	//       {
	//         from: path.resolve(__dirname, '../static'),
	//         to: 'static',
	//         ignore: ['.*']
	//       }
	// ])
  ],
  resolve: {
    alias: {
      '~': resolve(__dirname, 'src'),
	  '@': resolve(__dirname, 'src')
    },
    extensions: ['.js', '.vue', '.json', '.css']
  },
  devServer: {
    host: 'localhost',
    port: 8010,
    proxy: {
		'/qadb': {
		  // target: 'http://10.4.31.211:9512',
		 target: 'http://192.168.1.99:5002',
		  // target: 'http://3.kaikaiomg.applinzi.com/interface/api.php',
		  changeOrigin: true,
		  pathRewrite: {
			'^/qadb': ''
		  }
		},
      '/qadb2': {
        // target: 'http://10.4.31.211:9512',
		// target: 'http://127.0.0.1:9512',
		target: 'http://192.168.1.99:5002',
        changeOrigin: true,
        pathRewrite: {
          '^/kkapi': ''
        }
      },
	  '/kkupload': {
	    // target: 'http://10.4.31.211:9512',
	  		// target: 'http://127.0.0.1:9512',
	  		target: 'http://192.168.1.99:5002/upload',
	    changeOrigin: true,
	    pathRewrite: {
	      '^/kkupload': ''
	    }
	  }
    },
	
	
    historyApiFallback: {
      index: url.parse(options.dev ? '/assets/' : publicPath).pathname
    }
  },
  // devtool: options.dev ? '#eval-source-map' : '#source-map'
})
